
package com.work.db.dao;

import java.math.BigDecimal;
import java.util.*;

import com.work.db.*;
import com.work.db.entity.*;

public class OvertimeDaoImpl extends GenericDaoImpl<Overtime, Long> implements OvertimeDao {

	public OvertimeDaoImpl(Class<Overtime> type)
	{
		super(type);
	}

	@Override
	public List<Overtime> getOvertimes(Employer employer, int year)
	{
		return findAll();
	}
	
	@Override
	public int getOvertimeMinutesToTake(Employer employer, int year)
	{
		List<NativeQueryParam> params = new ArrayList<NativeQueryParam>();
		params.add(new NativeQueryParam("employerId", employer.getId()));
		params.add(new NativeQueryParam("year", year));

		return findOneByNativeQuery(SqlQuery.GET_OVERTIME_TO_TAKE, params, Integer.class);
	}

	@Override
	public int getTotalOvertimeMinutes(Employer employer)
	{
		List<NativeQueryParam> params = new ArrayList<NativeQueryParam>();
		params.add(new NativeQueryParam("employerId", employer.getId()));

		BigDecimal totalOvertimeMinutes =  findOneByNativeQuery(SqlQuery.GET_TOTAL_OVERTIME_MINUTES, params, BigDecimal.class);
		
		if (totalOvertimeMinutes != null) {
			return totalOvertimeMinutes.intValue();
		} 
	
		return -1;
	}
}